import React from 'react';
import {Link} from "react-router-dom";
import {Button} from "antd";
import GUtils from "@/utils";

const Config = (Action) => {
    const Handlers = {
        enabled({id,enabled,name}) {
            enabled=!enabled;
            let op = enabled ? "启用" :"禁用";
            GUtils.confirm(op,`确认${op}门店 [${name}] 吗?`,()=>{
                Action.enabled(id, enabled);
            });
        },
        sync(vo){
            GUtils.confirm("同步",`确认同步设备 [${vo.geekId} - ${vo.name}] 吗?`,()=>{
                Action.syncByGeekId(vo.geekId);
            });
        },
        testMqtt(vo){
            GUtils.confirm("测试MQTT",`确认对设备 [${vo.geekId} - ${vo.name}] 测试MQTT吗?该操作主要测试能否通过官网的MQTT中心控制开关`,()=>{
                Action.testMqtt(vo.geekId);
            });
        },
        bind(vo){
            Action.preBind(vo);
        },
        reset(vo){
            GUtils.confirm("恢复出厂设置",`确认对设备 [${vo.geekId} - ${vo.name}] 恢复出厂设置吗?恢复出厂设置后配网信息和自定义信息都会清空，请谨慎操作！`,()=>{
                Action.reset(vo.geekId);
            });
        }
    }
    const columns = [
       
        {title:"名称",dataIndex:"geekId",width:120,render(v, vo){
                return <div>
                    <div>{v}</div>
                    <div><b><a onClick={GUtils.goGeekDetail.bind(this,v)}>{vo.name}</a></b></div>
                </div>
            }},
        {title:"状态",dataIndex:"status",width:120, render(v, vo){
            return <div>
                <div>{GUtils.rendeGeekDeviceStatus(v)}</div>
                <div>同步时间：{GUtils.dateTimeFormatter(vo.syncTime)}</div>
            </div>
        }},
        {title:"信息",dataIndex:"status",width:120, render(v, vo){
                return <div>
                    <div>版本：{vo.geekVersion}</div>
                    <div>激活时间：{GUtils.dateTimeFormatter(vo.activeTime)}</div>
                    <div>下线时间：{GUtils.dateTimeFormatter(vo.offlineTime || vo.onlineTime)}</div>
                </div>
            }
        },
        {
            title: "关联设备", dataIndex: "deviceKey",width:120, render(v, vo){
            return <div>
                <div>门店：{vo.shopId ? <Link>{vo.shopName} ({GUtils.renderUID(vo.shopId)})</Link>:""}</div>
                <div>设备：：{vo.deviceId ? <Link>{vo.deviceName} ({GUtils.renderUID(vo.deviceId)})</Link>:""}</div>
            </div>
        }},
        {title: '操作',dataIndex: 'id',width: 150,render(id,vo, index){
            let {enabled} = vo;
                return <div>
                    <a className="mr-12" onClick={Handlers.sync.bind(this, vo, index)}>同步</a>
                    <a className="mr-12" onClick={Handlers.testMqtt.bind(this, vo, index)}>测试MQTT</a>
                    <a className="mr-12" onClick={Handlers.bind.bind(this, vo, index)}>绑定</a>
                    <a className="mr-12 danger" onClick={Handlers.reset.bind(this, vo, index)}>恢复出厂设置</a>
                </div>
            }
        },
    ];
    return {
        ...window.CONFIG.getPagerConfig(Action), columns
    };
};


export default Config;
